<script setup>
import { ref } from 'vue'

/**
 * 侧边栏菜单项配置
 * path: 对应的路由路径，需在路由器中定义
 * name: 显示的菜单名称
 * icon: 菜单图标 (可使用emoji或icon库)
 */
const menuItems = ref([
  { path: '/Hr/', name: '工作列表', icon: '📋' },
  { path: '/Hr/record', name: '操作日志', icon: '📝' },
])
</script>

<template>
  <div class="sidebar">
    <div class="sidebar-header">
      <h2 style="margin-top: 20px;margin-left: 60px">差旅审批</h2>
    </div>

    <nav class="sidebar-menu">
      <!-- 使用 router-link 进行路由跳转 -->
      <router-link
        v-for="item in menuItems"
        :key="item.path"
        :to="item.path"
        custom
        v-slot="{ navigate, isActive }"
      >
        <div
          class="menu-item"
          :class="{ active: isActive }"
          @click="navigate"
        >
          <span class="menu-icon">{{ item.icon }}</span>
          <span class="menu-text">{{ item.name }}</span>
        </div>
      </router-link>
    </nav>
  </div>
</template>

<style scoped>
/* 侧边栏样式 */
.sidebar {
  width: 260px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  z-index: 100; /* 确保在其他内容之上 */
}

.sidebar-header {
  padding: 30px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  margin: 0 0 5px 0;
  font-size: 20px;
  font-weight: 600;
}

.sidebar-header p {
  margin: 0;
  font-size: 14px;
  opacity: 0.8;
}

.sidebar-menu {
  flex: 1;
  padding: 20px 0;
  overflow-y: auto; /* 如果菜单项过多，允许滚动 */
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 15px 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
}

.menu-item:hover {
  background: rgba(255,255,255,0.1);
}

/* 使用 :deep() 或直接利用 router-link 的 .router-link-active 类 */
/* 这里使用 v-slot 提供的 isActive 来动态添加 class，更可控 */
.menu-item.active {
  background: rgba(255,255,255,0.2);
  border-left-color: white;
}

.menu-icon {
  font-size: 20px;
  margin-right: 15px;
  width: 25px;
  text-align: center;
}

.menu-text {
  font-size: 15px;
  font-weight: 500;
}
</style>
